package com.chiyoyo.multipay.framework;//package com.chil.framework.pay.example;
//
//import com.chil.framework.pay.core.client.PayClient;
//import com.chil.framework.pay.core.client.PayClientFactory;
//import com.chil.framework.pay.core.enums.channel.PayChannelEnum;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.context.annotation.Configuration;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * @author chilei
// *  支付客户端配置
// */
//@Slf4j
//@Configuration
//public class PayChannelService {
//
//    @PostConstruct
//    public void init() {
//        try {
//            // 查询可用的支付渠道，并初始化对应的PayClient对象
//            List<MgrAppPayModes> payModesList = sysPayModeService.getEnableMode();
//            for (MgrAppPayModes payMode : payModesList) {
//                String channelCode = payMode.getChannelCode();
//                String configStr = payMode.getConfig();
//                if (StringUtils.isBlank(channelCode) || StringUtils.isBlank(configStr)) {
//                    log.warn("PayChannel channelCode and config is empty");
//                    continue;
//                }
//                payClientFactory.createOrUpdatePayClient(channelCode, PayChannelEnum.parseConfig(channelCode, configStr));
//                // 将解析后的对象放入缓存中
//                payClientCache.put(channelCode, payClientFactory.getPayClient(channelCode));
//                log.info("PayChannel initialized successfully for code: {}", channelCode);
//            }
//        } catch (Exception e) {
//            log.error("Failed to initialize PayChannel: {}", e.getMessage(), e);
//        }
//    }
//
//    // 本地的缓存Map来存储已经解析过的PayClient对象
//    private final Map<String, PayClient> payClientCache = new ConcurrentHashMap<>();
//
//    @Resource
//    private PayClientFactory payClientFactory;
//    @Resource
//    private SysPayModeService sysPayModeService;
//
//    /**
//     * 根据支付渠道编码获取支付客户端对象
//     *
//     * @param channelCode 支付渠道编码
//     * @return 对应的支付客户端对象
//     */
//    public PayClient getPayClient(String channelCode) {
//        // 使用本地缓存，可以减少反序列化操作，提升性能
//        return payClientCache.get(channelCode);
//    }
//}
